
"""
AI 数据分析报告 - streamlit 服务
"""
from core.data_analyze.graph import build_graph
import streamlit as st

graph = build_graph()


def main():

    from tests.test_data import datasets

    st.title('AI数据分析')
    input_text = st.text_area('请输入分析任务的内容描述，例：分析历年教职工的人员情况', max_chars=500, help='最大长度为500字符')
    clicked = st.button("开始分析")
    if clicked:
        for event in graph.stream(
                input={
                    "auto_decision": True,
                    "max_retry_times": 3,
                    "cur_retry_times": 0,
                    "task_description": input_text,
                    "datasets": datasets,
                },
                stream_mode=["custom"]):
            (_, content) = event
            if isinstance(content, str):
                st.markdown(content)
            else:
                st.json(content)

if __name__ == "__main__":
    main()